package com.ustze.ocr.ocrtype.context;

import com.google.common.collect.Maps;
import com.ustze.ocr.ocrtype.enums.OcrType;
import com.ustze.ocr.ocrtype.request.OcrRequest;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author zk
 * @date 2025/04/11
 */
@Component
public class OcrTypeContext implements ApplicationContextAware {


    public static Map<OcrType, OcrRequest> OCR_MAP = Maps.newHashMap();

    public static OcrRequest getOcrType(OcrType ocrType) {
        return OCR_MAP.get(ocrType);
    }



    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        applicationContext.getBeansOfType(OcrRequest.class).forEach((k, v) ->{
            OCR_MAP.put(v.ocrType(), v);
        });
    }
}
